aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/scope-prompt/[scopes]/+server.ts
blob: 5521cf50c8f05324a2ad1450b8ab31767e41cf3b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { base } from '$app/paths';
import { checkScope } from '$lib/auth';
import { error, redirect } from '@sveltejs/kit';

export const GET = async (e) => {
  const scopes = e.params.scopes
    .split(' ')
    .flatMap((v) => v.split(','))
    .flatMap((v) => v.split('+'))
    .filter((v) => v);
  if (
    checkScope(
      await e.locals.auth(),
      scopes,
      true,
      base + '/scope-prompt/ok/if/' + scopes.join(',')
    )
  )
    throw redirect(303, base + '/scope-prompt/ok');
  else
    throw error(
      500,
      'In server mode, this branch should be unreachable. checkScope with getScopeOnFail should never return false outside of the client.'
    );
};